{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>编辑商品</h5>
                </div>
                <div class="ibox-content layui-form">
                    <div class="layui-row layui-col-space10 layui-form-item ">

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">商品名称：</label>
                            <div class="layui-input-block">
                                <input type="text" name="bg_name" lay-verify="required" placeholder="商品名称" class="layui-input" value="{$goods.bg_name}">
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8 form-group">
                            <label class="layui-form-label">类型：</label>
                            <div class="layui-input-block">
                                <input type="radio" name="bg_type" value="1" class="layui-input" title="花样青青" {$goods.bg_type == 1 ? 'checked' : ''}/>
                                <input type="radio" name="bg_type" value="2" class="layui-input" title="脖脸皮" {$goods.bg_type == 2 ? 'checked' : ''}/>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">产品码：</label>
                            <div class="layui-input-block">
                                <input type="text" name="bg_product_code" lay-verify="required" placeholder="产品码" class="layui-input" value="{$goods.bg_product_code}">
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">缩略图：</label>
                            <input type="hidden" name="bg_thumb" id="lay-img" lay-verify="image" value="{$goods.bg_thumb}">
                            <div class="layui-input-block">
                                <div id="lay-upload">上传图片</div>
                                <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                                    预览图：
                                    <div class="layui-upload-list" id="lay-list">
                                        <img class="layui-append-img" src="{$goods.bg_thumb}" onerror="this.src='/static/admin/images/no_img.jpg'">
                                    </div>
                                </blockquote>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md10">
                            <label class="layui-form-label">商品图集</label>
                            <div class="layui-input-block">
                                <input type="hidden" name="del" id="del2" value="">
                                <input type="hidden" id="hid2" value="{$goods.bg_images}">
                                <input type="hidden" name="bg_images" id="photo2" value="{$goods.bg_images}">
                                <div id="uploader2" class="container-s">
                                    <div class="queueList">
                                        <div class="placeholder">
                                            <div id="filePicker2"></div>
                                            <p>或将照片拖到这里</p>
                                        </div>
                                    </div>
                                    <div class="statusBar" style="display:none;">
                                        <div class="layui-progress layui-progress-big active-s" lay-showpercent="true">
                                            <div class="layui-progress-bar layui-bg-blue" lay-percent="0%">
                                            </div>
                                            <span></span>
                                        </div>
                                        <div class="info"></div>
                                        <div class="btns">
                                            <div id="goPicker2" class="filePicker2"></div>
                                            <div class="uploadBtn">开始上传</div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">一级分类：</label>
                            <div class="layui-input-block">
                                <select name="bg_first_cate" lay-search="" id="first_cate"  lay-filter="first_cate">
                                    <option value="">---- 请选择一级分类 ----</option>
                                    {foreach name="first_cate" item="vo"}
                                    <option value="{$vo.bgc_id}" {$vo.bgc_id == $goods.bg_first_cate ? 'selected' : ''}>{$vo.bgc_name}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">二级分类：</label>
                            <div class="layui-input-block xm-select-demo" id="second_cate">

                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8 form-group">
                            <label class="layui-form-label">商品状态：</label>
                            <div class="layui-input-block">
                                <input type="radio" name="bg_status" value="1" class="layui-input" title="上架" {$goods.bg_status == 1 ? 'checked' : ''}/>
                                <input type="radio" name="bg_status" value="2" class="layui-input" title="下架" {$goods.bg_status == 2 ? 'checked' : ''}/>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8 form-group">
                            <label class="layui-form-label">是否推荐：</label>
                            <div class="layui-input-block">
                                <input type="radio" name="bg_is_commend" value="2" class="layui-input" title="推荐" {$goods.bg_is_commend == 2 ? 'checked' : ''}/>
                                <input type="radio" name="bg_is_commend" value="1" class="layui-input" title="不推荐" {$goods.bg_is_commend == 1 ? 'checked' : ''}/>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8 form-group">
                            <label class="layui-form-label">销量显示：</label>
                            <div class="layui-input-block">
                                <input type="radio" name="bg_show_salenumber" value="1" class="layui-input" title="显示" {$goods.bg_show_salenumber == 1 ? 'checked' : ''}/>
                                <input type="radio" name="bg_show_salenumber" value="2" class="layui-input" title="不显示" {$goods.bg_show_salenumber == 2 ? 'checked' : ''}/>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8 form-group">
                            <label class="layui-form-label">库存显示：</label>
                            <div class="layui-input-block">
                                <input type="radio" name="bg_show_stock" value="1" class="layui-input" title="显示" {$goods.bg_show_stock == 1 ? 'checked' : ''}/>
                                <input type="radio" name="bg_show_stock" value="2" class="layui-input" title="不显示" {$goods.bg_show_stock == 2 ? 'checked' : ''}/>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">会员价格：</label>
                            <div class="layui-input-block">
                                <input type="text" name="bg_price" lay-verify="required" placeholder="会员价格" value="{$goods.bg_price}" class="layui-input" oninput="value=value.replace(/[^\d.]/g,'')">
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">原价：</label>
                            <div class="layui-input-block">
                                <input type="text" name="bg_old_price" lay-verify="required" placeholder="原价" value="{$goods.bg_old_price}" class="layui-input" oninput="value=value.replace(/[^\d.]/g,'')">
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">规格：</label>
                            <div class="layui-input-block">
                                <input type="text" name="bg_spec" lay-verify="required" placeholder="例如：10ml" value="{$goods.bg_spec}" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">库存：</label>
                            <div class="layui-input-block">
                                <input type="text" name="bg_stock" lay-verify="required" placeholder="库存" value="{$goods.bg_stock}" class="layui-input" oninput="value=value.replace(/[^\d]+/g,'')">
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">排序：</label>
                            <div class="layui-input-block">
                                <input type="text" name="bg_sort" value="{$goods.bg_sort}" placeholder="排序，值越大越靠前" class="layui-input" oninput="value=value.replace(/[^\d]+/g,'')">
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md10">
                            <label class="layui-form-label">商品详情：</label>
                            <div class="layui-input-block" id="LAY_editor" lay-verify="editor">
                                <p>{$goods.bg_content}</p>
                            </div>
                        </div>

                        <input type="hidden" value="{$bg_id}" name="bg_id">
                        <input type="hidden" value="{$goods.bg_first_cate}" name="f_cate">
                        <input type="hidden" value="{$s_cate}" name="s_cate">

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit="" lay-filter="component-form-element">保存
                                </button>
                                <!--<button class="layui-btn layui-btn-primary" onclick="history.go(-1)">关闭</button>-->
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

{include file="public/footer" /}
<script>
    var res_data = [];
    var data1 = [];
    var second_cate;
    wk.uploadImg({size:5,type:'png,jpg,jpeg',url:"{:url('Upload/upload')}",domain:""});
    var n2 = wk.uploads({num:5,type:'png,jpg,gif',attr:2,status:'update'})
    function imgDel2(e,obj,hid,del){
        wk.update_del(e,obj,hid,del,n2);
    }
    var editor = wk.wang({elem:'#LAY_editor'});
    layui.use(['form','upload','layedit','laydate'], function() {
        var form = layui.form;
        form.verify({
            editor:function(value,item){
                if(editor.txt.html() == '<p><br></p>'){
                    return '请填写内容';
                }
            }
        });

        form.on('submit(component-form-element)', function (data) {
            data.field.bg_content = editor.txt.html();
            $('.layui-btn').addClass('layui-disabled').attr('disabled','disabled');
            $.ajax({
                url:"{:url('goodsEdit')}",
                type:'post',
                dataType:'json',
                data:data.field,
                success:function(res){
                    if (res.code == 200) {
                        layer.msg(res.msg,{icon:1,time:1500,shade:0.1},function(index){
                            wk.layer_close();
                        });
                    } else {
                        wk.error(res.msg,'','$(".layui-btn").removeClass(\'layui-disabled\').removeAttr(\'disabled\');');
                    }
                }
            });
        });

        form.on('select(first_cate)', function (data){
            $.ajax({
                url:"{:url('admin/Base/boGoodsCate')}",
                dataType:"json",
                data:'id=' + data.value,
                type:'post',
                success:function (res){
                    if(res.code == 200){
                        res_data = res.msg;
                        $('#bg_second_cate').children().remove();
                        second_cate = xmSelect.render({
                            tips: '---- 请选择二级分类 ----',
                            filterable: true, // 开启搜索模式
                            toolbar: {show: true},
                            prop: {
                                name: 'bgc_name',
                                value: 'bgc_id',
                            },
                            el: '#second_cate',
                            language: 'zn',
                            data:res_data
                        });
                    }else{
                        wk.error(res.msg,'','$(".layui-btn").removeClass(\'layui-disabled\').removeAttr(\'disabled\');');
                    }
                }
            })
        });



    });
</script>
<script>
    // 进入页面，渲染页面
    var s_cate = $('input[name="s_cate"]').val();
    var f_cate = $('input[name="f_cate"]').val();
    $.ajax({
        url:"{:url('admin/Base/boGoodsCate')}",
        dataType:"json",
        data: {id: f_cate, s_cate:s_cate},
        type:'post',
        success:function (res){
            if(res.code == 200){
                res_data = res.msg;
                // 加载配置选项
                second_cate = xmSelect.render({
                    el: '#second_cate',
                    language: 'zn',
                    filterable: true, // 开启搜索模式
                    toolbar: {show: true},
                    prop: {
                        name: 'bgc_name',
                        value: 'bgc_id',
                    },
                    data:res_data
                });
                // 加载被选中的配置选项
                data1 = res.data;
                second_cate.setValue(data1);
            }else{
                wk.error(res.msg,'','$(".layui-btn").removeClass(\'layui-disabled\').removeAttr(\'disabled\');');
            }
        }
    });
</script>

</body>
</html>